#include "PlayerModel.h"

void PlayerModel::addCardsToOpenedTop(std::list<Card*> &topCards)
{
  openedCards_.splice(openedCards_.end(), topCards, topCards.begin(), topCards.end());
}

void PlayerModel::addCardsToClosedBottom(std::list<Card*> &bottomCards)
{
  closedCards_.splice(closedCards_.begin(), bottomCards, bottomCards.begin(), bottomCards.end());
}

void PlayerModel::clearOpenedCardList()
{
  openedCards_.clear();
}




PlayerModel::PlayerModel(): name_("")
{
}

void PlayerModel::addOpenedCardsToOpenedTop(PlayerModel &fromPlayer)
{
  addCardsToOpenedTop(fromPlayer.openedCards_);
}

void PlayerModel::addOpenedCardsToClosedBottom(PlayerModel &fromPlayer)
{
  addCardsToClosedBottom(fromPlayer.openedCards_);
}


void PlayerModel::addCardToOpenedTop(Card &topCard)
{
  openedCards_.push_back(&topCard);
  return;
}

void PlayerModel::addCardToClosedTop(Card &topCard)
{
  closedCards_.push_back(&topCard);
  return;
}

int PlayerModel::openCard()
{
  if (closedCards_.empty())
  {
    return 1;
  }
  openedCards_.push_back(closedCards_.back());
  closedCards_.pop_back();
  return 0;
}

int PlayerModel::getTopCardID() const
{
  if (openedCards_.empty())
  {
    return -1;
  }
  return openedCards_.back()->getID();
}

int PlayerModel::getTopCardColor() const
{
  if (openedCards_.empty())
  {
    return -1;
  }
  return openedCards_.back()->getColor();
}

int PlayerModel::getOpenedCardsNumber() const
{
  return openedCards_.size();
}

int PlayerModel::getClosedCardsNumber() const
{
  return closedCards_.size();
}

void PlayerModel::setName(const std::string name)
{
  name_ = name;
}

const std::string& PlayerModel::getName() const
{
  return name_;
}

void PlayerModel::setConnectTime(const time_t &time)
{
  connectTime_ = time;
}


bool PlayerModel::isWinner() const
{
  if (openedCards_.empty() && closedCards_.empty())
  {
    return true;
  }
  return false;
}

